package com.datounet.flutterapp.methodChannel;

import com.datounet.flutterapp.AgentWebActivity;
import com.datounet.flutterapp.Mgrs.BuglyManager;
import com.datounet.flutterapp.MainActivity;
import com.tencent.bugly.crashreport.CrashReport;

import java.util.Map;

import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;

/**
 * @author 41784
 */
public class OnMethodCallDelegate {

    void dispatch(MethodCall call, MethodChannel.Result result) {
        switch (call.method) {
            //处理来自Dart的方法调用
            case MethodTypes.INVOKE_DEMO:
                result.success("MethodChannelPlugin收到：" + call.arguments);
                //返回结果给Dart
                MethodChannelPlugin.invokeDartMethod(MethodTypes.INVOKE_DEMO,new MsgBean(1.73245445,"msg"),null);
                break;
            case MethodTypes.OPEN_AGENT_WEB:
                result.success("MethodChannelPlugin收到：" + call.arguments);
                //返回结果给Dart
                AgentWebActivity.openWebView(MainActivity.instance,call.arguments.toString());
                break;
            case MethodTypes.CHECK_UPDATE:
                BuglyManager.checkUpdate();
                break;
            case MethodTypes.ERR_REPORT:
                String errType = "";
                String err = "";
                String stackTrace = "";
                Map<String, String> extraInfo = null;
                if (call.hasArgument("type")) {
                    errType = call.argument("type");
                }
                if (call.hasArgument("error")) {
                    err = call.argument("error");
                }
                if (call.hasArgument("stackTrace")) {
                    stackTrace = call.argument("stackTrace");
                }
                if (call.hasArgument("extraInfo")) {
                    extraInfo = call.argument("extraInfo");
                }
                int category = 8;
                CrashReport.postException(category,errType,err,stackTrace,extraInfo);
                break;
            default:
                result.notImplemented();
        }
    }
}



